//
//  BackGroundScanView.m
//  Restaurant
//
//  Created by wanghuan on 15/5/7.
//  Copyright (c) 2015年 wanghuan. All rights reserved.
//

#import "BackGroundScanView.h"
#define BWith rect.size.width
#define BHeight rect.size.height
#define pathCenterX 60
#define pathCenterY 150

@implementation BackGroundScanView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

*/


- (void)drawRect:(CGRect)rect {
    
    
    CGContextRef contextTop=UIGraphicsGetCurrentContext();
    
//    CGContextSaveGState(contextTop);
    
    CGContextSetLineCap(contextTop, kCGLineCapRound);
    
    CGMutablePathRef pathTop = CGPathCreateMutable();
    CGPathMoveToPoint(pathTop, nil, 0, 0);
    CGPathAddLineToPoint(pathTop, nil, BWith, 0);
    CGPathAddLineToPoint(pathTop, nil, BWith, BHeight);
    CGPathAddLineToPoint(pathTop, nil, 0, BHeight);
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] setFill];
    CGContextAddPath(contextTop, pathTop);
    CGContextDrawPath(contextTop, kCGPathFill);
    
//挖去中间的正方形
    CGMutablePathRef pathCenter = CGPathCreateMutable();
    
    CGPathAddRect(pathCenter, nil, CGRectMake(pathCenterX, pathCenterY, APPWith-120, APPWith-120));
    CGContextAddPath(contextTop, pathCenter);
    CGContextSetBlendMode(contextTop, kCGBlendModeClear);
    CGContextDrawPath(contextTop, kCGPathFill);
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(pathCenterX, pathCenterY,APPWith-120 , APPWith-120)];
    
    view.layer.borderColor = [[UIColor whiteColor]CGColor];
    
    view.layer.borderWidth = 3;
    
    [self addSubview:view];
    
}

@end
